import {Directive, EventEmitter, HostListener, Input, Output, Type} from '@angular/core';
import {DialogService} from "primeng/api";

@Directive({
  selector: '[gnDialog]'
})
export class DialogDirective {

  @Input() content: Type<any>;
  @Input() header: string;
  @Input() width = "60%";
  @Input() height: string;
  @Input() data: any;

  @Output() onClose = new EventEmitter<any>();

  constructor(private dialogService: DialogService) {
  }

  @HostListener('click') onClick() {
    this.dialogService.open(this.content,
      {
        header: this.header,
        width: this.width,
        height: this.height,
        data: this.data
      }).onClose.subscribe(value => {
      if (value) {
        this.onClose.emit(value);
      }
    });
  }
}
